def singleton(cls, *args, **kw):
    instances = []

    def _singleton(*args, **kw):
        if len(instances) == 0:
            instances.append(cls(*args, **kw))
        return instances[0]

    return _singleton
